package per.turtle.common.mq.clients;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurationSelector;
import org.springframework.amqp.rabbit.connection.RabbitUtils;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * 接收者
 *
 * @author yuj
 */
@Component
@RabbitListener(queues = {"ip_address_queue"}, ackMode = "MANUAL")
public class RabbitReceiver extends RabbitUtils {

    @RabbitHandler
    public void process(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        System.out.println("Receiver  :  " + msg + "   ----   " + LocalDateTime.now());
        // 手动确认
        channel.basicAck(tag, false);
    }

}


